package com.niuke;

import com.leetCode.tree.TreeNode;


/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-12-16 14:53:41
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-12-16     张李鑫                     1.0         1.0 Version
 */
public class JZ27 {

    /**
     * 操作给定的二叉树，将其变换为源二叉树的镜像。
     * 数据范围：二叉树的节点数 0 \le n \le 10000≤n≤1000 ， 二叉树每个节点的值 0\le val \le 10000≤val≤1000
     * 要求： 空间复杂度 O(n)O(n) 。本题也有原地操作，即空间复杂度 O(1)O(1) 的解法，时间复杂度 O(n)O(n)
     */
    public static TreeNode Mirror(TreeNode pRoot) {
        // write code here
        process(pRoot);
        return pRoot;
    }

    private static void process(TreeNode pRoot) {
        if (pRoot == null) {
            return;
        }
        TreeNode left = pRoot.left;
        TreeNode right = pRoot.right;
        pRoot.left = right;
        pRoot.right = left;
        process(pRoot.left);
        process(pRoot.right);


    }

    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(3);
        TreeNode treeNode4 = new TreeNode(4);
        TreeNode treeNode5 = new TreeNode(5);


        treeNode1.left = treeNode2;
        treeNode1.right = treeNode3;
        treeNode2.left = treeNode4;
        treeNode2.right = treeNode5;


        TreeNode mirror = Mirror(treeNode1);

        System.out.println(123);
    }
}
